<template>
  <!-- table>tr中不能直接使用组件, 需要在tr的is属性指定组件名 -->
  <div>
    <table>
      <tr
        is="Hwex5"
        v-for="(val, index) in goodsArr"
        :key="index"
        :obj="val"
        :index="index"
      ></tr>
    </table>

    <p>All number：{{ total }}</p>
  </div>
</template>

<script>
import Hwex5 from "./components/Hwex5";
export default {
  data() {
    return {
      goodsArr: [
        {
          count: 0,
          goodsName: "Watermelon",
        },
        {
          count: 0,
          goodsName: "Banana",
        },
        {
          count: 0,
          goodsName: "Orange",
        },
        {
          count: 0,
          goodsName: "Pineapple",
        },
        {
          count: 0,
          goodsName: "Strawberry",
        },
      ],
    };
  },

  computed: {
    total() {
      return this.goodsArr.reduce((sum, obj) => ((sum += obj.count * 1), 0));
    },
  },

  components: {
    Hwex5,
  },
};
</script>

<style>
</style>